package acm.pta13;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
// 测试别人代码是否内存超限
public class Main {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    // 记录剧情点
    static class Edge {
        int[] temp;

        public Edge(int[] temp) {
            this.temp = temp;
        }
    }

    public static void main(String[] args) throws IOException {
        int n = nextInt();
        int m = nextInt();
        Edge[] edges = new Edge[100001];
        for (int i = 1; i <= n; i++) {
            int k = nextInt();
            int[] a = new int[k + 1];
            for (int j = 1; j <= k; j++) {
                a[j] = nextInt();
            }
            edges[i] = new Edge(a);
        }
        // 存档
        int[] backup = new int[101];
        // 剧情点编号都从 1 号开始
        int pos = 1;
        for (int i = 0; i < m; i++) {
            int k = nextInt();
            int v = nextInt();
            if (k == 0) {
                pos = edges[pos].temp[v];
            } else if (k == 1) {
                backup[v] = pos;
                System.out.println(pos);
            } else if (k == 2) {
                pos = backup[v];
            }
        }
        // 最后到达的剧情点编号
        System.out.println(pos);
        System.in.read();
    }
}

